package com.pureut.storage.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.pureut.storage.dto.PickingSchemeDto;
import com.pureut.storage.dto.SchemeDto;
import com.pureut.storage.service.PickingSchemeService;
import com.pureut.storage.vo.PickingSchemeRelationVo;
import com.pureut.storage.vo.PickingSchemeVo;
import com.pureut.storage.vo.SchemeVo;
import com.sale.common.core.domain.R;
import com.sale.common.core.web.controller.BaseController;
import com.sale.common.log.annotation.Log;
import com.sale.common.log.enums.BusinessType;
import com.sale.common.mybatis.core.page.PageQuery;
import com.sale.common.mybatis.core.page.TableDataInfo;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/***
 * 拣货方案控制层
 * Author:C
 * Date:2022/12/21 15:46
 * @DESC
 */
@RestController
@RequestMapping("/picking-scheme")
public class PickingSchemeController extends BaseController {

    @Resource
    PickingSchemeService pickingSchemeService;

    /**
     * 获取拣货方案列表
     */
    //@SaCheckPermission("warehouse:pickingPlan:list")
    @GetMapping("/list")
    public TableDataInfo<PickingSchemeDto> getList(PickingSchemeVo pickingSchemeVo, PageQuery pageQuery) {
        //查询拣货方案列表
        return pickingSchemeService.getList(pickingSchemeVo, pageQuery);
    }

    /**
     * 新增
     */
    //@SaCheckPermission("warehouse:pickingPlan:add")
    @Log(title = "新增", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public R<Void> add(@Validated @RequestBody PickingSchemeVo pickingSchemeVo) {
        return toAjax(pickingSchemeService.addPickingScheme(pickingSchemeVo));
    }

    /**
     * 修改
     */
    //@SaCheckPermission("warehouse:pickingPlan:edit")
    @Log(title = "修改", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    public R<Void> update(@Validated @RequestBody PickingSchemeVo pickingSchemeVo) {
        return toAjax(pickingSchemeService.updatePickingScheme(pickingSchemeVo));
    }

    /**
     * 查看
     */
    //@SaCheckPermission("warehouse:pickingPlan:query")
    @GetMapping("/view/{id}")
    public R<PickingSchemeDto> getView(@PathVariable("id") Long id) {
        return R.ok(pickingSchemeService.getView(id));
    }

    /**
     * 关联
     */
    //@SaCheckPermission("warehouse:pickingPlan:relation")
    @Log(title = "关联", businessType = BusinessType.INSERT)
    @PostMapping("/relation")
    public R<Void> relation(@Validated @RequestBody PickingSchemeRelationVo pickingSchemeRelationVo) {
        return toAjax(pickingSchemeService.relation(pickingSchemeRelationVo));
    }

    /**
     * 解绑
     */
    //@SaCheckPermission("warehouse:pickingPlan:relieve")
    @Log(title = "解绑", businessType = BusinessType.UPDATE)
    @GetMapping("/relieve/{id}")
    public R<Void> relieve(@PathVariable("id") Long id) {
        return toAjax(pickingSchemeService.relieve(id));
    }

    /**
     * 删除
     */
    //@SaCheckPermission("warehouse:pickingPlan:remove")
    @Log(title = "删除", businessType = BusinessType.DELETE)
    @DeleteMapping("/delete/{ids}")
    public R<Void> delete(@PathVariable("ids") String ids) {
        return toAjax(pickingSchemeService.deletePickingScheme(ids));
    }

    /**
     * 根据物料编码、关联信息、默认标志获取仓库-库区-库位-批次号信息
     */
   @PostMapping("/getSchemeData")
   public R<SchemeDto> getSchemeData(@RequestBody SchemeVo schemeVo) {
       return R.ok(pickingSchemeService.getSchemeData(schemeVo));
   }
}

